package com.spider.silence.output;

import com.spider.silence.constant.Constant;
import com.spider.silence.itf.output.Writer;
import com.spider.silence.utils.ZipUtils;

import java.io.File;
import java.util.Map;

/**
 * @author 夏茂轩
 * @package com.spider.silence.output
 * @Date 2017/6/21 9:46
 */
public class FileWriter implements Writer{

    @Override
    @Deprecated
    public boolean write(String path, String fileName, String content) throws Exception {
        throw new Exception("废弃方法！禁止使用");
    }

    @Override
    public boolean write(String path, String fileName, String content, Map<String, File> files) throws Exception {
        String file_N=Constant.FILE_FOLDER+"//" +path.replaceAll("_","//" )+"//";
        File file =new File(file_N);
        if(!file.exists()){
            file.mkdirs();
        }
        file=new File(file_N+fileName);
        java.io.FileWriter fw=new java.io.FileWriter(file);
        fw.write(content);
        fw.flush();
        fw.close();
        String name=path+"_"+fileName;
        String file_zip_name=Constant.FILE_FOLDER+"//"+path.replaceAll("_","//" ).replace("speeches","org_file")+"//" ;
        File fileZip= ZipUtils.ZipMultiFileByPath(files,file_zip_name,path+"_"+fileName);
        return true;
    }
}
